using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using InfoExpress.HIV.WinApp.Utils;
using InfoExpress.WinApp.Utils;

namespace InfoExpress.HIV.WinApp.Popups
{
  public partial class FrmDsPhacDo : XtraForm
  {
    private DataTable _dtbDsPhacDo = null;
    private int _benhNhanId = 0;

    public FrmDsPhacDo()
    {
      InitializeComponent();
    }

    public FrmDsPhacDo(int benhNhanId)
      : this()
    {
      _benhNhanId = benhNhanId;
    }

    #region Event Handlers

    private void FrmDsPhacDo_Load(object sender, EventArgs e)
    {
      LoadData();
    }

    #region Data Loading

    private void bwDataLoading_DoWork(object sender, DoWorkEventArgs e)
    {
      try
      {
        DataSet dtsDsPhacDo = GlobalCache.ThayDoiPhacDoService.DsPhacDo(_benhNhanId);
        _dtbDsPhacDo = dtsDsPhacDo.Tables[0];
      }
      catch (Exception ex)
      {
        Logger.LogCritical("FrmDsPhacDo::bwDataLoading_DoWork", ex, "General", null);
      }
    }

    private void bwDataLoading_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
      Cursor = Cursors.Default;
      MainFormUtils.StopProgress();

      if (_dtbDsPhacDo != null)
      {
        gcDsBenhNhan.DataSource = _dtbDsPhacDo;
        MainFormUtils.SetLoadedStatus();
      }
      else
      {
        MainFormUtils.SetLoadedFailedStatus();
        UIUtils.ShowCannotLoadDataMessage();
      }
    }

    #endregion DataLoading BackgroundWorker

    #endregion

    #region Helper Methods

    private void LoadData()
    {
      Cursor = Cursors.WaitCursor;
      MainFormUtils.StartProgress();
      MainFormUtils.SetLoadingStatus();
      bwDataLoading.RunWorkerAsync();
    }

    #endregion

    
  }
}